gpNamespace.TimerLayer = cc.Layer.extend({
    timeInit: 0,
    timeSec: 0,

    currentAt: null,

    timeShow: null,
    armature: null,
    background: null,

    clockPosition: [cc.p(455, 220), cc.p(1040, 565), cc.p(228, 565)],
    timePosition: [cc.p(455, 217),cc.p(1040, 562),  cc.p(228, 562)],
    
    ctor: function (timeInit) {
        this.timeInit = timeInit;
        this.timeSec = timeInit;

        this._super();
        this.init();
    },

    init: function () {
        this._super();
        
        cc.log(" TimerLayer init:");
//        var background = new cc.Sprite("#ddz_jm_022u.png");
        var background = new cc.Sprite(gpNamespace.pdkgame.Game_buttonclock);
        background.attr({
            x: 91 / 2,
            y: 80 / 2
        });
        this.addChild(background, 1, "background");
        background.setVisible(false);
        this.background = background;
        cc.log("background:" + background);
        //var backgroundSize = background.getContentSize();
        //
        ////秒
        //var timeShow = new ddzNamespace.NumLayer(this.timeSec, 19, 50);
        //timeShow.setPosition(backgroundSize.width / 2, backgroundSize.height / 2 - 3);
        //background.addChild(timeShow, 1, "timeShow");
        //
        //this.timeShow = timeShow;

        ////动画
        //var armature = new ccs.Armature("ddz_sos_01a");
        //armature.getAnimation().playWithIndex(0);
        //armature.getAnimation().setSpeedScale(1);
        //armature.setScale(1);
        //armature.setAnchorPoint(0.5, 0.5);
        //armature.setVisible(false);
        //this.addChild(armature, 1, "warn");
        //this.armature = armature;

        //秒
        var timeShow = new tyNamespace.NumLayer(this.timeSec, 18, 75); //设置黑色的数字
        timeShow.setVisible(false);
        this.addChild(timeShow, 1, "timeShow");
        this.timeShow = timeShow;
    },

    setTimeSec: function (sec) {
        this.timeInit = sec;
        this.timeSec = sec;
        this.background.setVisible(false);
    },

    updateTime: function () {
        var runningScene = cc.director.getRunningScene();

        if (this.timeSec > 0) {
            this.timeSec--;
            if (this.timeSec <= 5 && runningScene.getChildByName("gameEndBackgroundLayer") == undefined) {
//                dzmjNamespace.playEffect(dzmjNamespace.soundRes.AlertEffect, false);
            }

            this.timeShow.reloadNum(this.timeSec);
        }
    },

    setCurrentPosition: function (orderIndex) {
        cc.log("timer layer setCurrentPosition" + orderIndex);

        this.background.setVisible(true);

        this.timeShow.setVisible(true);

        this.unschedule(this.updateTime);

        this.timeSec = this.timeInit;

        this.schedule(this.updateTime, 1);

        this.timeShow.reloadNum(this.timeSec);

        this.background.setPosition(this.clockPosition[orderIndex]);
        this.timeShow.setPosition(this.timePosition[orderIndex]);
    }
});